package com.ego.order.controller;

import com.ego.order.pojo.Order;
import com.ego.order.service.OrderService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @PostMapping
    public ResponseEntity<Long> submit(@RequestBody Order order) {
        Long orderId = orderService.createOrder(order);
        return ResponseEntity.ok(orderId);
    }

    @GetMapping("/code/{orderId}")
    public ResponseEntity<String> code(@PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderService.getPayCodeUrl(orderId));
    }

    @GetMapping("/status/{orderId}")
    public ResponseEntity<Integer> queryStatus(@PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderService.getOrderStatus(orderId));
    }
}
